/** * -------------------------------------------------------------------------------- * PROPRIETARY & CONFIDENTIAL * -------------------------------------------------------------------------------- * Plugin Name: Yokko Ultimate SEO Engine * Description: Custom high-performance SEO system (Auto-Title, Auto-Desc, * OG-Tags, Schema, and XML Sitemap). * Author: Yokko * Version: 2.5 (Ultimate Protected) * Copyright: (c) 2026 Yokko. All rights reserved. * * NOTICE: All information contained herein is the property of Yokko. * Unauthorized copying or distribution of this file via any medium is * strictly prohibited. * -------------------------------------------------------------------------------- */ if ( ! class_exists( 'WP_Pro_Custom_SEO' ) ) { class WP_Pro_Custom_SEO { public function __construct() { add_action( 'add_meta_boxes', [ $this, 'add_seo_meta_box' ] ); add_action( 'save_post', [ $this, 'save_seo_data' ] ); add_action( 'wp_head', [ $this, 'render_seo_meta_tags' ], 1 ); add_filter( 'pre_get_document_title', [ $this, 'custom_seo_title' ], 15 ); add_action( 'init', [ $this, 'register_sitemap_route' ] ); add_action( 'template_redirect', [ $this, 'render_sitemap' ] ); add_filter( 'wp_sitemaps_enabled', '__return_false' ); } public function add_seo_meta_box() { $screens = [ 'post', 'page' ]; foreach ( $screens as $screen ) { add_meta_box( 'wp_pro_seo_box', 'Pengaturan SEO', [ $this, 'render_meta_box_html' ], $screen, 'advanced', 'high' ); } } public function render_meta_box_html( $post ) { wp_nonce_field( 'wp_pro_seo_save_data', 'wp_pro_seo_meta_nonce' ); $seo_title = get_post_meta( $post->ID, '_pro_seo_title', true ); $seo_desc = get_post_meta( $post->ID, '_pro_seo_desc', true ); $seo_canonical = get_post_meta( $post->ID, '_pro_seo_canonical', true ); $seo_robots = get_post_meta( $post->ID, '_pro_seo_robots', true ); echo ''; echo '
'; echo ''; echo ''; echo ''; } public function save_seo_data( $post_id ) { if ( ! isset( $_POST['wp_pro_seo_meta_nonce'] ) || ! wp_verify_nonce( $_POST['wp_pro_seo_meta_nonce'], 'wp_pro_seo_save_data' ) ) return; if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; if ( isset( $_POST['pro_seo_title'] ) ) update_post_meta( $post_id, '_pro_seo_title', sanitize_text_field( $_POST['pro_seo_title'] ) ); if ( isset( $_POST['pro_seo_desc'] ) ) update_post_meta( $post_id, '_pro_seo_desc', sanitize_textarea_field( $_POST['pro_seo_desc'] ) ); if ( isset( $_POST['pro_seo_canonical'] ) ) update_post_meta( $post_id, '_pro_seo_canonical', esc_url_raw( $_POST['pro_seo_canonical'] ) ); if ( isset( $_POST['pro_seo_robots'] ) ) update_post_meta( $post_id, '_pro_seo_robots', sanitize_text_field( $_POST['pro_seo_robots'] ) ); } public function custom_seo_title( $title ) { if ( is_singular() ) { $custom = get_post_meta( get_the_ID(), '_pro_seo_title', true ); if ( ! empty( $custom ) ) return $custom; return get_the_title() . ' - ' . get_bloginfo( 'name' ); } elseif ( is_category() || is_tag() ) { return single_term_title('', false) . ' - ' . get_bloginfo( 'name' ); } return $title; } private function generate_auto_description( $post_content ) { $text = wp_strip_all_tags( strip_shortcodes( $post_content ) ); $text = str_replace( [ "\n", "\r", "\t" ], ' ', $text ); if ( mb_strlen( $text, 'UTF-8' ) > 155 ) $text = mb_substr( $text, 0, 155, 'UTF-8' ) . '...'; return trim( $text ); } public function render_seo_meta_tags() { $seo_desc = ''; $seo_robots = 'index, follow'; $canonical_url = ''; $og_image = ''; $final_title = ''; if ( is_singular() ) { global $post; $seo_title_custom = get_post_meta( $post->ID, '_pro_seo_title', true ); $seo_desc = get_post_meta( $post->ID, '_pro_seo_desc', true ); $seo_robots = get_post_meta( $post->ID, '_pro_seo_robots', true ); if ( empty( $seo_desc ) ) $seo_desc = $this->generate_auto_description( $post->post_content ); $final_title = ! empty( $seo_title_custom ) ? $seo_title_custom : get_the_title() . ' - ' . get_bloginfo( 'name' ); $canonical_url = get_permalink(); $og_image = has_post_thumbnail() ? get_the_post_thumbnail_url($post->ID, 'large') : ''; } elseif ( is_category() || is_tag() ) { $seo_desc = term_description(); $final_title = single_term_title('', false) . ' - ' . get_bloginfo( 'name' ); $canonical_url = get_term_link( get_queried_object() ); } elseif ( is_home() || is_front_page() ) { $seo_desc = get_bloginfo( 'description' ); $final_title = get_bloginfo( 'name' ) . ' - ' . $seo_desc; $canonical_url = home_url( '/' ); } if ( ! empty( $seo_desc ) ) echo '' . "\n"; echo '' . "\n"; remove_action( 'wp_head', 'rel_canonical' ); echo '' . "\n"; echo '' . "\n"; if ( ! empty( $og_image ) ) echo '' . "\n"; } public function register_sitemap_route() { add_rewrite_rule( '^sitemap\.xml$', 'index.php?pro_custom_sitemap=1', 'top' ); add_rewrite_tag( '%pro_custom_sitemap%', '1' ); } public function render_sitemap() { if ( get_query_var( 'pro_custom_sitemap' ) ) { header( 'Content-Type: application/xml; charset=utf-8' ); echo ''; echo '